const Joi = require('joi')

//定义用户名，密码，id，昵称，邮箱，头像的验证规则
const username = Joi.string().alphanum().min(2).max(20).required()
const password = Joi.string().pattern(/^[\S]{6,15}$/).required()
const id = Joi.string().min(1).required()
const nickname = Joi.string().min(2).max(20).required()
const email = Joi.string().email().required()
const avatar = Joi.string().required()

//定义验证注册和登录表单数据的规则对象
exports.reg_login_schema = Joi.object({ username, password })
//验证规则对象-更新用户基本信息
exports.update_userinfo_schema = Joi.object({ id, nickname, email })
//验证规则对象-重置密码
exports.update_password_schema = Joi.object({
    oldPwd: password,
    //新密码不能与旧密码相同，并同时需要符合密码的验证规则
    newPwd: Joi.not(Joi.ref('oldPwd')).concat(password)
})
//验证规则对象-更新头像
exports.update_avatar_schema = Joi.object( { avatar })
//验证规则对象-添加用户
exports.add_user_schema = Joi.object({ username, password, nickname })
//验证规则对象-修改用户
exports.update_user_schema = Joi.object({ username, nickname })



